package com.heima.comment.listener;

import com.alibaba.fastjson.JSON;
import com.heima.comment.dto.CommentStreamMessage;
import com.heima.comment.service.ICommentService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

/**
 * @Author WSJ
 * @Date 2022-03-25-15:19
 * @Version 1.0 （版本号）
 */
@Service
public class CommentResultListener {
 @Autowired
 private ICommentService commentService;

    @KafkaListener(topics = "comment_repay_result_topic")
    public void result(ConsumerRecord<String, String> record) {
        String key = record.key();
        String value = record.value();
        CommentStreamMessage commentStreamMessage = JSON.parseObject(value, CommentStreamMessage.class);
        commentService.update(commentStreamMessage);
    }
}
